<template>
	<view>
		<video id="myVideo" :src="information" :poster='poster' controls object-fit='fill'></video>
		<!-- <view class="box">
			<view class="title">课程内容</view>
			<view class="substance">
				为帮助广大教师完善授课体系、提高教育水平，教育部教育管理中心携手百度课程，将于2024年10月-2024-12月为大家献上‘信息技术与教育教学深度融合典型案例研究中心’之中小学教师公开课。</view>
		</view> -->
		<view v-if="list.length > 0">
			<view class="nav" v-for="(item,index) in list" :key="index" @click="onclick(item,index)">
				<view class="left">
					<view class="details">
						<view class="title">{{item.name}}</view>
						<view style="margin-top: 10rpx;display: flex;align-items: center;">
							<view class="speciality" v-if="item.pay == 1">金额：￥{{item.price}}</view>
							<view class="Customer" @click.stop="consulting()">咨询客服：
								<image src="https://img.wilmer.com.cn/admin/2024/4-3/Group%20332.png" mode=""></image>
							</view>
						</view>
					</view>
				</view>
				<view class="right_text" v-if="item.pay != 1">
					支付：<text>￥{{item.price}}</text>
				</view>
				<image class="right" v-if="item.pay == 1"
					:src="listIndex==index?'https://img.wilmer.com.cn/admin/2024/3-26/Group%20322.png':'https://img.wilmer.com.cn/admin/2024/3-26/Group%20324.png'"
					mode=""></image>
			</view>
		</view>
		<image v-if="list.length == 0" class="NoData" src="https://img.wilmer.com.cn/admin/2024/3-20/WechatIMG19.jpg"
			mode=""></image>
		<view :style="{height: safeArea + 'px'}"></view>
		<!-- 二维码 -->
		<u-popup :show="Qrshow" mode="center" :round="10" bgColor='transparent' zIndex='10075' @close="Qrclose"
			@touchmove.stop.prevent="moveHandle">
			<view class="box-img">
				<image src="https://img.wilmer.com.cn/admin/2024/4-3/1.jpg" mode=""></image>
				<image @click="handleLongPress" style="width: 280rpx;height: 280rpx;" :src="qrCode" mode="">
				</image>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import {
		listVideo
	} from '@/api/system/Video.js'
	import {
		createVideoOrder,
		videoPay
	} from '@/api/system/bank_request.js'
	export default {
		data() {
			return {
				safeArea: 0, // 底部安全距离
				list: [], // 视频列表
				listIndex: 0, // 
				information: '', // 视频地址
				poster: "", // 封面
				qrCode: "",
				Qrshow: false,
				payForm: {
					code: '',
					prise: '',
					conId: ''
				},
			}
		},
		onLoad(option) {
			uni.setNavigationBarTitle({
				title: option.type
			});
			this.getList(option.type)
			this.getConfigKey("Qcode").then(response => {
				this.qrCode = response.msg;
			});
		},
		onShow() {
			// 获取底部安全距离
			let res = uni.getSystemInfoSync();
			this.safeArea = res.screenHeight - res.safeArea.bottom;
		},
		methods: {
			getList(val) {
				uni.showLoading({
					title: '加载中'
				});
				listVideo({
					classify: val == '查征信' ? 2 : 1
				}).then(res => {
					setTimeout(() => {
						uni.hideLoading();
					}, 500)
					this.list = res.data
					if (this.listIndex == 0) {
						this.information = res.data[0].url
						this.poster = res.data[0].image
					}
				})
			},
			moveHandle() {
				return false;
			},
			Qrclose() {
				this.Qrshow = false
			},
			consulting() {
				this.Qrshow = true
			},
			async onclick(item, index) {
				if (item.pay == 1) {
					uni.showLoading({
						title: '加载中'
					});
					setTimeout(() => {
						uni.hideLoading();
					}, 1500)
					this.listIndex = index
					this.information = item.url
					this.poster = item.image
				} else {
					let that = this
					uni.showLoading({
						title: '加载中'
					});
					// 下单
					let res = await createVideoOrder({
						videoId: item.id,
						payAmount: item.price
					})
					// 去支付
					let pay = await videoPay({
						orderNum: res.msg
					})
					let wxPay = JSON.parse(pay.data)
					uni.requestPayment({
						provider: 'wxpay',
						timeStamp: wxPay.timeStamp,
						nonceStr: wxPay.nonceStr,
						paySign: wxPay.paySign,
						package: wxPay.package,
						signType: wxPay.signType,
						success: function(res) { // 支付成功回调
							setTimeout(() => {
								uni.hideLoading();
							}, 500)
							uni.showToast({
								title: '支付成功',
							})
							that.listIndex = index
							that.getList()
							that.information = that.list[index].url
							that.poster = that.list[index].image
						},
						fail: function(err) { // 支付失败回调
							uni.hideLoading();
						}
					});
				}
			},
		}
	}
</script>

<style lang="scss">
	page {
		width: 100%;
		height: auto;
		background: #F8F8F8;
		overflow-x: hidden;
	}
</style>


<style lang="scss" scoped>
	#myVideo {
		width: 100vw;
		height: 440rpx;
		margin: 20rpx auto 0;
		display: block;
	}

	.box {
		width: 686rpx;
		height: 210rpx;
		background: #F9F9F9;
		margin: 50rpx auto 0;
		padding-top: 30rpx;

		.title {
			text-align: center;
			font-family: PingFang SC;
			font-size: 28rpx;
			font-weight: 400;
			color: #666666;
		}

		.substance {
			width: 628rpx;
			font-family: PingFang SC;
			font-size: 24rpx;
			font-weight: 400;
			color: #666666;
			line-height: 1.2;
			margin: 20rpx auto 0;
		}
	}

	.uni-ellipsis-1 {
		display: -webkit-box;
		overflow: hidden;
		text-overflow: ellipsis;
		word-wrap: break-word;
		white-space: normal !important;
		-webkit-line-clamp: 1;
		-webkit-box-orient: vertical;
	}

	.nav {
		margin-top: 12rpx;
		width: 100vw;
		height: 160rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		background-color: #fff;
		border-bottom: 12rpx solid #F8F8F8;

		.left {
			margin-left: 48rpx;
			display: flex;

			.details {
				display: flex;
				flex-direction: column;

				.title {
					font-family: PingFang SC;
					font-size: 36rpx;
					font-weight: 500;
					letter-spacing: 0.03em;
					color: #666666;
				}

				.speciality {
					font-family: PingFang SC;
					font-size: 24rpx;
					font-weight: 400;
					color: #999999;
				}

				.Customer {
					margin-left: 20rpx;
					font-family: PingFang SC;
					font-size: 24rpx;
					font-weight: 400;
					color: #999999;
					display: flex;
					align-items: center;

					image {
						width: 40rpx;
						height: 36rpx;
						margin-left: 4rpx;
					}
				}
			}
		}

		.right {
			width: 44rpx;
			height: 40rpx;
			min-width: 44rpx;
			min-height: 40rpx;
			margin-right: 44rpx;
		}

		.right_text {
			margin-right: 46rpx;
			font-family: PingFang SC;
			font-size: 24rpx;
			font-weight: 400;
			color: #999999;

			text {
				font-family: PingFang SC;
				font-size: 32rpx;
				font-weight: 400;
				color: #319AF5;
			}
		}
	}

	.NoData {
		display: block;
		width: 400rpx;
		height: 318rpx;
		margin: 40rpx auto 0;
	}

	.box-img {
		width: 480rpx;
		height: 368rpx;
		overflow: hidden;
	}

	.box-img image:nth-child(1) {
		width: 480rpx;
		height: 368rpx;
	}

	.box-img image:nth-child(2) {
		position: absolute;
		left: 50%;
		z-index: 999;
		transform: translateX(-50%);
		margin-top: 10rpx;
	}
</style>